package aiyh.utils.dao;

import aiyh.utils.Util;
import aiyh.utils.entity.ApiConfigDetailDTO;
import aiyh.utils.entity.ApiConfigMainDTO;
import aiyh.utils.entity.MultiLanguageDTO;
import weaver.conn.RecordSet;

import java.util.List;

/**
 * @author EBU7-dev1-ayh
 * @create 2021/10/14 0014 12:09
 * 数据库交互
 */


public class UtilDao {
	private final RecordSet rs = new RecordSet();


	public ApiConfigMainDTO getApiConfigMain(String id) {
		String query = "select id,workflow_type,api_url,api_name from uf_api_param_config where id = ?";
		rs.executeQuery(query, id);
		return Util.recordeSet2Entity(rs, ApiConfigMainDTO.class, true);
	}

	public List<ApiConfigDetailDTO> getApiConfigDetail(int mainId) {
		String query = "select dt.id,dt.line_num,dt.param_name,dt.param_type,dt.object_child,dt.parent_line,dt.change_rule, " +
				"dt.param_value,wf.fieldname workflow_field,wf.tablename tablename,dt.array_sql " +
				"from uf_api_param_config_dt1 dt " +
				"left join workflow_field_table_view wf on wf.id = dt.workflow_field " +
				"where mainid = ? and (are_use is null or are_use = 1)";
		rs.executeQuery(query, mainId);
		return Util.recordeSet2Array(rs, ApiConfigDetailDTO.class, true);
	}

	public List<MultiLanguageDTO> queryLanguage(int groupId) {
		String query = "select * from uf_multi_language_dt1 where mainid = ?";
		rs.executeQuery(query, groupId);
		return Util.recordeSet2Array(rs, MultiLanguageDTO.class, true);
	}

}
